/*!
 *  \file       SignalFilter.cpp
 *  \brief      Implementazione della classe \c SignalFilter
 *  \author     Davide Scola <S2299453@studenti.unige.it>
 *  \author	Minetti Alberto <S3064777@studenti.unige.it>
 *  \version    1.0
 *
 */
#include <vector>
#include <complex>

#include "Fft.cpp"

#include "ISignalNoise.hpp"
#include "ISignalGenerator.hpp"
#include "InputSignal.hpp"

#include "IFilterGenerator.hpp"
#include "SignalFilter.hpp"

using namespace std;


/*!
 *  \brief      Applica il generatore dato al segnale
 */
template< class tType, template< typename > class tFilter > void
SignalFilter< tType, tFilter >::doit( std::vector< std::complex< tType > > &signal )
{
  tFilter< tType> generator( signal );
  
  transform( (&signal)->begin( ), (&signal)->end( ), (&signal)->begin( ), generator );
}


/*!
 *  \brief	Costruttore della classe \c SignalFilter
 *
 *  \see	SignalFilter< tType >::SignalFilter( SignalFilter< tType > const& other )
 */
template< class tType, template< typename > class tFilter >
SignalFilter< tType, tFilter >::SignalFilter( void )
{
}

/*!
 *  \brief      Costruttore di copia della classe \c SignalFilter
 *  \param[in]	other	filtro da copiare
 *
 *  \see	SignalFilter< tType >::SignalFilter( void )
 */
template< class tType, template< typename > class tFilter >
SignalFilter< tType, tFilter >::SignalFilter( SignalFilter< tType, tFilter > const& other )
{
}


/*!
 *  \brief      Operatore di assegnazione della classe \c SignalFilter
 */
template < typename tType, template< typename > class tFilter > SignalFilter< tType, tFilter >&
SignalFilter< tType, tFilter >::operator=( const SignalFilter< tType, tFilter >& other )
{
   if (this == &other) {
       return *this;
   }
   
   return *this;
}


/*!
 *  \brief      Applica il filtro al segnale dato
 */
template< class tType, template< typename > class tFilter > void
SignalFilter< tType, tFilter >::applyFilter( InputSignal< tType > &input )
{
  Fft< tType > fft( input.size() );
  
  fft.compute( input );
  
  this->doit( fft );	// applico il generatore
  
  fft.invert();
  
  for( unsigned long int i = 0; i < input.size(); ++i )
    input[i] = fft[i].real();
}
